package com.compass.mobile.presenters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.framework.ext.visible
import com.compass.mobile.framework.utils.DateUtils
import com.compass.mobile.models.PatientBean
import dp2px
import setUrlRound

/**
 * Description： 就诊人 presenter
 * Date:2024/6/12 15:02
 */
class PatientPresenter : Presenter() {

    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view =
            LayoutInflater.from(viewGroup.context)
                .inflate(R.layout.layout_item_patient, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is PatientBean) {
            val vh = viewHolder as ViewHolder
            vh.tvName.text = item.name
            if (item.id == "10086") {
                vh.llInfo.gone()
                vh.llAdd.visible()

            } else {
                if (item.defaultStatus == 1) vh.imgDef.visible() else vh.imgDef.gone()
                vh.avatar.setUrlRound(item.avatar, dp2px(5f))
                if (item.sex == "1") vh.tvSex.text ="性别：男" else vh.tvSex.text = "性别：女"
                vh.tvAge.text ="年龄：${item.age}岁"
                vh.createTime.text ="创建日期：${DateUtils.conversionTime(item.createTime,DateUtils.FORMAT_FOUR)}"
                vh.llInfo.visible()
                vh.llAdd.gone()
            }

        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {}
    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvName: TextView
        var tvSex: TextView
        var tvAge: TextView
        var createTime: TextView
        var imgDef: ImageView
        var avatar: ImageView
        var llInfo: RelativeLayout
        var llAdd: LinearLayout

        init {
            tvAge = view.findViewById(R.id.tvAge)
            createTime = view.findViewById(R.id.createTime)
            tvSex = view.findViewById(R.id.tvSex)
            tvName = view.findViewById(R.id.tvName)
            avatar = view.findViewById(R.id.avatar)
            imgDef = view.findViewById(R.id.imgDef)
            llInfo = view.findViewById(R.id.llInfo)
            llAdd = view.findViewById(R.id.llAdd)

        }
    }
}